﻿namespace iOSClub.CheckInApi.DataModels;

[Serializable]
public class UserInfoModel
{
    public string Name { get; set; }

    public string Id { get; set; }

    /// <summary>
    /// Admin : 管理员
    /// Minister : 部长
    /// Department : 部员成员
    /// Member : 普通成员
    /// </summary>
    public string Identity { get; set; }

    public List<CheckModel> Checks { get; init; }
    public List<SeriesModel> Series { get; init; }

    /// <summary>
    /// 连续打卡天数
    /// </summary>
    public int CheckCount { get; set; }

    /// <summary>
    /// 本月打卡次数
    /// </summary>
    public int MonthCheck { get; set; }

    public UserInfoModel(UserModel user)
    {
        Name = user.Name;
        Id = user.Id;
        Identity = user.Identity;
        Checks = user.Checks;
        Series = user.Series;
        var (thisYear, thisMonth, _) = DateTime.Today.AddHours(8);
        MonthCheck = Checks.Count(x => x.CheckTime.Month == thisMonth && x.CheckTime.Year == thisYear);
        if (Checks.Count is 1 or 0)
        {
            CheckCount = Checks.Count;
        }

        CheckCount = 1;

        for (var i = Checks.Count - 1; i > 0; i--)
        {
            if (Checks[i].CheckTime.Day == Checks[i - 1].CheckTime.Day + 1)
            {
                CheckCount++;
                continue;
            }

            break;
        }
    }
}